package com.thoughtworks.conference.utils;

import com.thoughtworks.conference.model.TalkInfo;
import com.thoughtworks.conference.model.TrackSession;

import java.util.Calendar;

/**
 * <p>Title: 会议安排管理的工具类</p>
 * <p>Description:用于处理会议管理的数据</p>
 *
 * @author <a href="mailTo:bingxuewulei@outlook.com">wanglei</a>
 * @version 1.0
 * @history: Created by wanglei on  2019/4/25
 */
public class ConferenceUtils {
    /**
     * 计算获得时间对象
     * @param hours 小时
     * @param minutes 分钟
     * @return
     */
    public static Calendar getCalendarTime(int hours, int minutes) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, hours);
        cal.set(Calendar.MINUTE, minutes);
        return cal;
    }

    /**
     * 获取下一个会议的开始时间
     * @param currentStartTime 当前开始时间
     * @param currentTalk 当前任务
     * @return
     */
    public static Calendar getNextStartTime(Calendar currentStartTime, TalkInfo currentTalk) {
        Calendar newTime = Calendar.getInstance();
        newTime.set(Calendar.HOUR_OF_DAY, currentStartTime.get(Calendar.HOUR_OF_DAY));
        newTime.set(Calendar.MINUTE, currentStartTime.get(Calendar.MINUTE));
        newTime.add(Calendar.MINUTE, currentTalk.getTalkTimeIntValue());
        return newTime;
    }

    /**
     * 判断当前时间段是否有时间可以安排当前会议
     * @param talkInfo 会议任务信息
     * @param trackSession 会议安排的时间段
     * @return
     */
    public static boolean hasFreeTimeForTalk(TalkInfo talkInfo, TrackSession trackSession) {
        return  trackSession.getTotalCapacity() > talkInfo.getTalkTimeIntValue();
    }
}
